<template>
  <div class="wrapper-right">
    <Title title="小区攻坚计划（营业部）" />
    <el-table :data="tableData" height="94%" style="width: 100%" ref="tableRef">
      <el-table-column prop="communityName" label="小区名称" width="auto" align="center"
        show-overflow-tooltip></el-table-column>
      <el-table-column prop="marketingTime" label="攻坚时间" width="100" align="center"></el-table-column>
      <el-table-column label="攻坚目标" width="auto" align="center">
        <el-table-column prop="penetrationRate" label="宽带渗透率" width="94" align="center"></el-table-column>
        <el-table-column prop="fttrTarget" label="FTTR" width="60" align="center"></el-table-column>
        <el-table-column prop="convergenceTarget" label="全量融合" width="75" align="center"></el-table-column>
        <el-table-column prop="fans" label="绑粉数" width="60" align="center"></el-table-column>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
  import { countByRanking } from "@/api/home";
  import { getDeptTree } from "@/api/system/user";
  import { leftList } from "@/api/system/target";
  import Title from "./Title";
  import store from "@/store";
  export default {
    name: "HomeRight",
    components: { Title },
    data() {
      return {
        postData: 
          {
            // deptId: 219,
            deptId: store.state.user.deptId, //将缓存的用户id赋值给userId，用于查询营销人员
            status: 0,
            delFlag: 0,
          },
        timeList: [
          {
            value: "week",
            label: "最近一周",
          },
          {
            value: "month",
            label: "最近一个月",
          },
          {
            value: "quarter",
            label: "最近一个季度",
          },
          {
            value: "year",
            label: "最近一年",
          },
        ],
        //小区业务数据统计筛选条件
        communityBusiness: {
          salesDepartment: "雁南分局",
          baoQu: "",
          community: "",
          time: "",
        },

        //小区业务数据统计排名
        tableData: [
          {
            community: "城关区天庆嘉园B区",
            timeRange: "8.5-8.6",
            task1: "1",
            task2: "1",
            task3: "1",
            task4: "1",
          },
          {
            community: "城关区天庆嘉园B区",
            timeRange: "8.5-8.6",
            task1: "1",
            task2: "1",
            task3: "1",
            task4: "1",
          },
          {
            community: "城关区天庆嘉园B区",
            timeRange: "8.5-8.6",
            task1: "1",
            task2: "1",
            task3: "1",
            task4: "1",
          },
          {
            community: "城关区天庆嘉园B区",
            timeRange: "8.5-8.6",
            task1: "1",
            task2: "1",
            task3: "1",
            task4: "1",
          },
          {
            community: "城关区天庆嘉园B区",
            timeRange: "8.5-8.6",
            task1: "1",
            task2: "1",
            task3: "1",
            task4: "1",
          },
          {
            community: "城关区天庆嘉园B区",
            timeRange: "8.5-8.6",
            task1: "1",
            task2: "1",
            task3: "1",
            task4: "1",
          },
          {
            community: "城关区天庆嘉园B区",
            timeRange: "8.5-8.6",
            task1: "1",
            task2: "1",
            task3: "1",
            task4: "1",
          },
          {
            community: "城关区天庆嘉园B区",
            timeRange: "8.5-8.6",
            task1: "1",
            task2: "1",
            task3: "1",
            task4: "1",
          },
          {
            community: "城关区天庆嘉园B区",
            timeRange: "8.5-8.6",
            task1: "1",
            task2: "1",
            task3: "1",
            task4: "1",
          },
          {
            community: "城关区天庆嘉园B区",
            timeRange: "8.5-8.6",
            task1: "1",
            task2: "1",
            task3: "1",
            task4: "1",
          },
          {
            community: "城关区天庆嘉园B区",
            timeRange: "8.5-8.6",
            task1: "1",
            task2: "1",
            task3: "1",
            task4: "1",
          },
          {
            community: "城关区天庆嘉园B区",
            timeRange: "8.5-8.6",
            task1: "1",
            task2: "1",
            task3: "1",
            task4: "1",
          },
          {
            community: "城关区天庆嘉园B区",
            timeRange: "8.5-8.6",
            task1: "1",
            task2: "1",
            task3: "1",
            task4: "1",
          },
          {
            community: "城关区天庆嘉园B区",
            timeRange: "8.5-8.6",
            task1: "1",
            task2: "1",
            task3: "1",
            task4: "1",
          },
          {
            community: "城关区天庆嘉园B区",
            timeRange: "8.5-8.6",
            task1: "1",
            task2: "1",
            task3: "1",
            task4: "1",
          },
        ],
        tableDatacs: [
          {
            rank: "1",
            community: "城关区天庆嘉园B区",
            accomplish: "113.33%",
            isOk: "是",
          },
          {
            rank: "2",
            community: "国泰嘉园",
            accomplish: "96.67%",
            isOk: "否",
          },
          {
            rank: "3",
            community: "兰宁小区",
            accomplish: "92.00%",
            isOk: "否",
          },
          {
            rank: "4",
            community: "南昌路经济适用房",
            accomplish: "72.00%",
            isOk: "否",
          },
          {
            rank: "5",
            community: "金雁花园",
            accomplish: "58.00%",
            isOk: "否",
          },
          {
            rank: "6",
            community: "地震局东岗西路家属院",
            accomplish: "56.00%",
            isOk: "否",
          },
          {
            rank: "7",
            community: "南昌路科苑一区家属楼",
            accomplish: "44.00%",
            isOk: "否",
          },
          {
            rank: "8",
            community: "南面滩安置房",
            accomplish: "25.00%",
            isOk: "否",
          },
          {
            rank: "9",
            community: "省广电总台专家公寓",
            accomplish: "13.33%",
            isOk: "否",
          },
          {
            rank: "10",
            community: "城关区天庆嘉园A区",
            accomplish: "0%",
            isOk: "否",
          },
          {
            rank: "11",
            community: "城关区天庆嘉园C区",
            accomplish: "0%",
            isOk: "否",
          },
          {
            rank: "12",
            community: "雁栖园",
            accomplish: "0%",
            isOk: "否",
          },
          {
            rank: "13",
            community: "红叶城",
            accomplish: "0%",
            isOk: "否",
          },
          {
            rank: "14",
            community: "康乐花园",
            accomplish: "0%",
            isOk: "否",
          },
          {
            rank: "15",
            community: "红星紫郡",
            accomplish: "0%",
            isOk: "否",
          },
          {
            rank: "16",
            community: "安居小区南区",
            accomplish: "0%",
            isOk: "否",
          },
          {
            rank: "17",
            community: "城关区政府家属院",
            accomplish: "0%",
            isOk: "否",
          },
          {
            rank: "18",
            community: "广电家园",
            accomplish: "0%",
            isOk: "否",
          },
          {
            rank: "19",
            community: "南河新省人民医院家属院村",
            accomplish: "0%",
            isOk: "否",
          },
          {
            rank: "20",
            community: "南河新村",
            accomplish: "0%",
            isOk: "否",
          },
        ],

        //营业部列表
        salesDepartmentList: [
          {
            value: 0,
            label: "营业部总量",
          },
          {
            value: 1,
            label: "红星营业部",
          },
          {
            value: 2,
            label: "张苏滩营业部",
          },
        ],
        baoQuListR: [],
      };
    },
    created() {
      // this.getDeptTree(100);
      // this.countByRanking({ deptId: 100 });
      this.getLeftListData(this.postData)
    },
    methods: {

      getLeftListData(postData) { 
        leftList(postData).then(res => { 
          this.tableData = res.data;
        })
      },
      /** 查询部门下拉树结构 */
      async getDeptTree(deptId) {
        getDeptTree({ deptId: deptId }).then((response) => {
          var treeData = response.data.children;

          if (deptId == 100) {
            this.salesDepartmentList = [
              {
                deptName: response.data.deptName,
                deptId: response.data.deptId,
              },
              {
                deptName: response.data.children[0].deptName,
                deptId: response.data.children[0].deptId,
              },
              {
                deptName: response.data.children[1].deptName,
                deptId: response.data.children[1].deptId,
              },
            ];

            console.log(this.salesDepartmentList, "树结构");
            // this.deptOptions = treeData;
          } else {
            this.baoQuListR = response.data.children;
          }
        });
      },
      countByRanking(data) {
        countByRanking(data).then((response) => {
          console.log(response.data, "小区业务数据统计排名");
          response.data.sort((a, b) => {
            return (
              b.percent.substring(0, b.percent.length - 1) -
              a.percent.substring(0, a.percent.length - 1)
            );
          });
          response.data.forEach((item, index) => {
            /*  this.tableData.push({
              rank: index + 1,
              community: item.deptName,
              accomplish: item.percent,
              isOk: item.finished,
           }); */
          });
        });
      },
      //时间切换
      handleCommunityTime() {
        this.$message("数据完善中...");
      },
      //包区数据选中
      handleCommunityBusinessBaoquChange(value) {
        this.tableData = [];
        this.countByRanking({ deptId: value });
      },
      //小区业务数据统计排名
      handleCommunityBusinessChange(value) {
        this.baoQuListR = [];
        this.tableData = [];
        this.communityBusiness.baoQu = "";
        this.postData.deptId = value;
        this.countByRanking({ deptId: value });
        this.getDeptTree(value);
      },
      getRanking(rank) {
        if (rank == "1") {
          return "first";
        } else if (rank == "2") {
          return "second";
        } else if (rank == "3") {
          return "third";
        } else {
          return "other";
        }
      },
    },
  };
</script>

<style scoped lang="scss">
  .wrapper-right {
    width: 100%;
    height: 100%;
  }

  .filtr-selects {
    display: flex;
    justify-content: end;
  }

  .filter-selects-righttop {
    position: absolute;
    top: -2px;
    right: -5px;
    width: 56%;

    .bottom-selects {
      width: 33%;
    }
  }

  .first {
    color: #fff;
    background-color: #fd4f4f;
    /* 红色背景 */
  }

  .second {
    color: #fff;
    background-color: #fcca00;
    /* 黄色背景 */
  }

  .third {
    color: #fff;
    background-color: #a2ef4d;
    /* 绿色背景 */
  }

  .other {
    color: #fff;
    background-color: #cecece;
    /* 灰色背景 */
  }

  .isOk-yes {
    display: flex;
    align-items: center;
    justify-content: center;

    img {
      width: 16px;
      height: 16px;
      margin-left: 5px;
    }
  }

  .isOk-no {
    display: flex;
    align-items: center;
    justify-content: center;

    img {
      width: 16px;
      height: 16px;
      margin-left: 5px;
    }
  }
</style>